var express = require("express");
var router = express.Router();
const { trendModel } = require("../model/ljb");
/* GET users listing. */
router.get("/", function (req, res, next) {
  res.send("respond with a resource");
});
router.get("/trend", async (req, res) => {
  const body = req.query;
  const data = await trendModel.find(body).sort({ createDate: -1 });
  res.send({ code: 200, msg: "success", data });
});

// 发布
router.post("/addfb", async (req, res) => {
  let body = req.body;
  body.name = "gpp1";
  body.profileImage = "https://avatars.githubusercontent.com/u/11142323?v=4";
  console.log(body);
  await trendModel.create(body);
  // const data = await trendModel.find(body);
  res.send({ code: 200, msg: "success" });
});

router.get("/searchlist", async (req, res) => {
  console.log(2222);
  const body = req.query;

  console.log(body.keyword, "vvvv");
  const data = await trendModel.find({ title: { $regex: body.keyword } });
  res.send(data);
});
module.exports = router;
